import numpy as np
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import *
from pyecharts.components import Table
from pyecharts.faker import Faker
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.options import ComponentTitleOpts

# 数据读取
df = pd.read_excel('C:/Users/DELL/Desktop/课程/数据清洗期末实训/实训资料/data/服饰行业粉丝关注焦点.xlsx')
df_2 = pd.read_excel('C:/Users/DELL/Desktop/课程/数据清洗期末实训/实训资料/data/服饰行业粉丝地域分布.xlsx')

# 服装行业名称
cloth_categories = ['连衣裙', '夹克', '蕾丝雪纺衫', '背心吊带', '西装西裤', '羽绒服',
                    '牛仔裤', '休闲裤', '半身裙', '连体裤', 'T恤', '针织衫/毛衣',
                    '衬衫', '卫衣/绒衫', 'polo衫', '风衣', '运动卫衣/套头衫',
                    '马甲', '棉衣', '运动茄克/外套', '大衣', '皮衣']

# 筛选出所有指定的服装类别的数据
df_cloth_region = df_2[df_2['行业名称'].isin(cloth_categories)]

# 计算每个省份的用户占比，分别计算每个行业
province_distribution = {}
for category in cloth_categories:
    category_data = df_cloth_region[df_cloth_region['行业名称'] == category]
    distribution = category_data.groupby('省份')['占比'].sum().round(2).reset_index()
    province_distribution[category] = distribution

# 找出每个省份的主要关注行业
main_focus = df_cloth_region.groupby(['省份', '行业名称'])['占比'].sum().reset_index()
main_focus = main_focus.loc[main_focus.groupby('省份')['占比'].idxmax()]
print(main_focus)



